package com.small.nacos.common.task;

/**
 * @Author zhoujin
 * @Date 2022/11/12 14:09
 */
public abstract class AbstractDelayTask implements NacosTask{

    /**
     * 任务间隔
     */
    private long taskInterval;

    /**
     * 最后一次执行时间
     */
    private long lastProcessTime;

    public long getTaskInterval() {
        return taskInterval;
    }

    public void setTaskInterval(long taskInterval) {
        this.taskInterval = taskInterval;
    }

    public long getLastProcessTime() {
        return lastProcessTime;
    }

    public void setLastProcessTime(long lastProcessTime) {
        this.lastProcessTime = lastProcessTime;
    }

    /**
     * 合并任务
     * @param task
     */
    public abstract void merge(AbstractDelayTask task);

    @Override
    public boolean shouldProcess() {
        return (System.currentTimeMillis() - this.lastProcessTime >= this.taskInterval);
    }
}
